home *** CD-ROM | disk | FTP | other *** search
/ 500 MB Nyheder Direkte fra Internet 2 / 500 MB nyheder direkte fra internet CD 2.iso / start / data / text / numeric.txt < prev    next >
Text File  |  1994-09-21  |  14KB  |  419 lines

  1.  
  2.                      ERRORS
  3.   Computers make mathematical errors. Here's why.
  4.  
  5.      Twin problems that confuse the computer
  6.   Look at this pair of problems. . . . 
  7. Problem 1: solve the equation x²-4x+4 = 0.
  8. Problem 2: solve the equation x²-4x+3.9999999 = 0.
  9. Those two problems resemble each other. The only difference is 
  10. that where the second problem says 3.9999999, the first problem 
  11. says 4. But the correct solutions to the problems are quite 
  12. different from each other:
  13. The correct solution to problem 1 is ``x = 2''.
  14. The correct solution to problem 2 is "x = 1.9996838 or x = 
  15. 2.0003162".
  16.   Unfortunately, problem 1 looks so similar to problem 2 that the 
  17. computer can hardly tell the difference. Some computers treat 
  18. 3.9999999 as if it were 4. If you ask such a computer to solve 
  19. problem 2, it will solve problem 1 instead, and its answer to 
  20. problem 2 will therefore be wrong.
  21.   Here's another pair of problems. . . . 
  22. Problem 3: solve the equation (x-1)*(x-2)*(x-3)*(x-4)*...*(x-20) 
  23. = 0.
  24.  
  25. Problem 4: solve the equation (x-1)*(x-2)*(x-3)*(x-4)*...*(x-20) 
  26. -2-23*x19 = 0.
  27. Those two problems resemble each other. In fact, if you ``expand 
  28. the polynomial'', you'll see that problem 3 can be rewritten like 
  29. this:
  30. x20 - 210x19 + ... = 0.
  31. Problem 4 can be rewritten like this:
  32. x20 - (210+2-23)x19 + ... = 0.
  33. So problem 4 differs from problem 3 just by saying 210+2-23 
  34. instead of 210. Since 2-23 is a tiny number (approximately 
  35. .0000001), some computers can't tell the difference between 210 
  36. and 210+2-23, can't distinguish problem 4 from problem 3, and say 
  37. the same answer to problem 4 as to problem 3. But the correct 
  38. solutions to the two problems are different:
  39. The correct solution to problem 3 is ``x=1 or x=2 or x=3 or x=4 
  40. or ... or x=20''.
  41.  
  42. The correct solution to problem 4 is ``x=1.000 or x=2.000 or 
  43. x=3.000 or x=4.000 or x=5.000 or x=6.000 or x=7.000 or x=8.007 or 
  44. x=8.917 or x=10.095±.644i or x=11.794±1.652i or x=13.992±1.519i 
  45. or x=16.731±2.813i or x=19.502±1.940i or x=20.847''. (i denotes 
  46. the square root of -1.)
  47.   Here's one more case. . . . 
  48. Problem 5: solve the simultaneous equations ``913x+659y=254 and 
  49. 780x+563y=217''.
  50. Problem 6: solve the simultaneous equations ``913x+659y=254 and 
  51. 780x+563y=216.999''.
  52. Although the problems are almost identical (so that some 
  53. computers can't distinguish them from each other), the correct 
  54. solutions are quite different:
  55. The correct solution to problem 5 is ``x=1    and y=-1''.
  56. The correct solution to problem 6 is ``x=.341 and y=-.087''.
  57.   That last case of ``confusing twins'' leads to this fascinating 
  58. paradox. . . . Suppose you tell your friendly computer to 
  59. ``guess'' an x and y to solve problem 5:
  60. 913x + 659y = 254
  61. 780x + 563y = 217
  62. If the computer guesses ``x=.999 and y=-1.001'', it finds:
  63. 913x + 659y = 252.428
  64. 780x + 563y = 215.757
  65. But if the computer guesses ``x=.341 and y=-.087'' instead, it 
  66. finds:
  67. 913x + 659y = 254
  68. 780x + 563y = 216.999, which is about 217
  69. The computer therefore deduces that its second guess is almost 
  70. perfect and much better than its first guess. But ___ here's the 
  71. paradox ___ the second guess is not
  72. better than the first guess; the first guess is better, because 
  73. the correct solution is ``x=1 and y=-1'', which is closer to the 
  74. first guess.
  75.  
  76.                                                     Reduce round-off error
  77.                                                      By the laws 
  78. of mathematics, 5+.14+.14+.14 should be the same as 
  79. .14+.14+.14+5. But a calculator that holds just two significant 
  80. digits gives different answers:
  81. 5+.14+.14+.14              .14+.14+.14+5
  82.  
  83.     5.0                         .14
  84.     +.14                       +.14
  85.     5.1                         .28
  86.     +.14                       +.14
  87.     5.2                         .42
  88.     +.14                      +5.0
  89.     5.3                        5.4
  90. Since the correct answer is 5.42, the calculation on the right is 
  91. more accurate. The general rule is: when adding a list of 
  92. numbers, you'll get more accuracy if you begin with the numbers 
  93. closest to 0. The rule is valid even on a top-quality computer, 
  94. although the computer's inaccuracies are not so obvious.
  95.                                                      By the laws 
  96. of mathematics, (31/5 - 31/7)*70 is 4:
  97.   1     7
  98.  3  = 3
  99.   5    35
  100.  
  101.  
  102.   1     5
  103. -3  = 3
  104.   7    35
  105.  
  106.         2
  107.           * 70 = 4
  108.        35
  109. But if we try that calculation on our two-digit calculator, we 
  110. get a totally different answer:
  111.   1
  112.  3  = 3+.2  = 3.2
  113.   5
  114.  
  115.  
  116.   1
  117. -3  = 3+.14 = 3.1
  118.   7              
  119.                .1 * 70 = 7.0
  120. The general warning is: when you subtract two numbers that are 
  121. almost equal (like 31/5 and 31/7), few of the digits in your 
  122. answer will be correct. The warning is valid even on a 
  123. top-quality computer, although the computer's inaccuracies are 
  124. not so obvious.
  125.  
  126.               ESTIMATES
  127.   The computer can estimate an answer.
  128.  
  129.          Connecting the dots
  130.   Suppose you're given the value of y when x is 1, 2, 3, 4, and 
  131. 5:
  132. Suppose you'd like to make an ``intelligent guess'' as to the 
  133. value of y when x is 1.5, 3.01, 100, -400, and other values. 
  134. Guessing y for an in-between x (such as 1.5 and 3.01) is called 
  135. interpolation; guessing y for a very large x or a very small x 
  136. (such as 100 and -400) is called extrapolation.
  137.   One way to guess is to connect the points with line segments:
  138. That's called piecewise linear estimation.
  139.   You get a much smoother picture by using a cubic spline:
  140. P1 and P6 are parts of straight lines. P2, P3, P4, and P5 are 
  141. parts of four different cubics (third-degree polynomials), chosen 
  142. so that, at the point where Pi meets Pi+1, Pi has the same 
  143. derivative and second derivative as Pi+1. (The term 
  144. ``derivative'' is defined by calculus.)
  145.                                                  Least-square line
  146.                                          Suppose you're given 
  147. these approximate values of y:
  148. To estimate y for other values of x, you could use piecewise 
  149. linear estimation or a cubic spline. But notice the points lie 
  150. almost on a straight line:
  151. The points aren't exactly on that line; the errors in the y 
  152. values are e1, e2, e3, e4, and e5. The line's squared error is 
  153. e1² + e2² + e3² + e4² + e5². This line has a larger squared 
  154. error:
  155. The line having the smallest squared error is called the 
  156. least-square line, and is considered to be the line that best 
  157. approximates the data.
  158.  
  159.            SOLVE EQUATIONS
  160.   The computer can solve equations.
  161.  
  162.           Single equations
  163.   Suppose you want to solve a tough equation, such as 2x+x3=20. 
  164. Rewrite it to make the right side be 0:
  165. 2x+x3-20=0
  166. Let f(x) denote the left side of the equation:
  167. f(x) is 2x+x3-20
  168. So the equation you want to solve is f(x)=0. Here's a way to 
  169. solve it ___ called the secant method. . . . 
  170.   Let x1 and x2 be your favorite numbers. Graph f(x1) and f(x2):
  171. Let x3 be where the line connecting those points hits the x axis:
  172. Graph f(x3); it's probably close to 0:
  173. Connect the x2 point to the x3 point, to find x4:
  174. Connect the x3 point to the x4 point, to find x5:
  175. Probably you'll get closer and closer to the point where f(x) is 
  176. 0.
  177.   A different method, called Muller's method, uses parabolas 
  178. instead of straight lines. . . . 
  179.                                          Let x1, x2, and x3 be 
  180. your three favorite numbers. A common choice is -.5, .5, and 0. 
  181. Graph f(x1), f(x2), and f(x3):
  182. Draw the parabola that passes through those points:
  183. The parabola hits the x axis at two points (although the points 
  184. might be what mathematicians call "imaginary"). Let x4 be at one 
  185. of those points. For best results, choose the point that's closer 
  186. to the origin:
  187. Graph f(x4):
  188. Draw a parabola through the x2, x3, and x4 points, to find x5:
  189. Probably you'll get closer to the place where f(x) is 0.
  190.                                          Usually, Muller's method 
  191. moves toward the solution more rapidly than the secant method. It 
  192. can even find complex, ``non-real'' solutions, since the x value 
  193. where the parabola hits the x axis might be of the form a+bi, 
  194. where i denotes the square root of -1. (If you're interested in 
  195. just solutions that are real, pretend b is 0.)
  196.                                          Using either the secant 
  197. method or Muller's, suppose you finally find a solution of the 
  198. equation 2x+x3-20=0. Let s1 denote that solution. To hunt for 
  199. additional solutions, try solving this equation:
  200.  x  3
  201. 2 +x -20
  202.          = 0
  203.   x-s
  204.      1
  205. If you find a solution of that new equation, call it s2, and 
  206. solve this equation:
  207.    x  3
  208.   2 +x -20  
  209.              = 0
  210. (x-s )(x-s )
  211.     1     2
  212. If that produces a solution s3, solve
  213.       x  3
  214.      2 +x -20     
  215.                    = 0
  216. (x-s )(x-s )(x-s )
  217.     1     2     3
  218. to find s4. The solutions s1, s2, s3, s4, etc., are all solutions 
  219. of the original equation.
  220.   The round-off error will be less if |s1| < |s2| < |s3| < |s4| < 
  221. .... So when you hunt for solutions, begin by trying to find the 
  222. solutions closest to zero. That's why, when Muller's parabola 
  223. hits the x axis in two points, you should pick the point that's 
  224. closer to zero. And that's why a common choice for x1, x2, and x3 
  225. is numbers near zero.
  226.  
  227.        Simultaneous equations
  228.   Try to solve these simultaneous linear equations:
  229. 8x +  y -  z =  8
  230. 2x +  y + 9z = 12
  231.  x - 7y + 2z = -4
  232.   An obvious way is Gauss-Jordan elimination. Eliminate the first 
  233. coefficient:
  234.      1    1                             1
  235.  x +  y -  z =  1      (I multiplied by  )
  236.      8    8                             8
  237.  
  238. 2x +  y + 9z = 12
  239.  
  240.  x - 7y + 2z = -4
  241. Eliminate everything below it:
  242.      1    1      
  243.  x +  y -  z =  1
  244.      8    8      
  245.  
  246.      3   37
  247.       y +  z = 10      (I subtracted twice the first row)
  248.      4    4
  249.  
  250.     57   17
  251.    -  y +  z = -5      (I subtracted the first row)
  252.      8    8
  253. Eliminate the first coefficient in the second row:
  254.      1    1      
  255.  x +  y -  z =  1
  256.      8    8      
  257.  
  258.          37    40                       4
  259.       y +  z =         (I multiplied by  )
  260.           3     3                       3
  261.  
  262.     57   17
  263.    -  y +  z = -5
  264.      8    8
  265. Eliminate everything above and below it:
  266.           5     2                    1
  267.  x      -  z = -       (I subtracted   times the second row)
  268.           3     3                    8
  269.  
  270.          37    40
  271.       y +  z =
  272.           3     3
  273.  
  274.                                 57
  275.          90z = 90      (I added    times the second row)
  276.                                  8
  277. Eliminate the first coefficient in the third row:
  278.           5     2
  279.  x      -  z = -
  280.           3     3
  281.  
  282.          37    40
  283.       y +  z =
  284.           3     3
  285.  
  286.                                          1
  287.            z = 1       (I multiplied by   )
  288.                                         90
  289. Eliminate everything above it:
  290.                                 5
  291.  x           = 1       (I added   times the third row)
  292.                                 3
  293.  
  294.                                      37
  295.       y      = 1       (I subtracted    times the third row)
  296.                                       3
  297.  
  298.            z = 1
  299. That's the solution. (It's depressing that so much computation 
  300. was needed, to get such a simple solution!)
  301.   In that example, I pivoted on the first coefficient of the 
  302. first equation, then the first coefficient of the second 
  303. equation, and finally the first coefficient of the third 
  304. equation. To reduce the computer's round-off error, it's better 
  305. at each stage to pivot on the coefficient that has the largest 
  306. absolute value, relative to the coefficients in its row. For 
  307. example, at this stage ___ 
  308.      1    1      
  309.  x +  y -  z =  1
  310.      8    8      
  311.  
  312.      3   37
  313.       y +  z = 10
  314.      4    4
  315.  
  316.     57   17
  317.    -  y +  z = -5
  318.      8    8
  319. it would have been better to pivot on -57/8 than on 3/4,  since 
  320. 57/8 divided by 17/8 is bigger than 3/4 divided by 37/4.
  321.                                          Now let's go back to the 
  322. original equations ___ 
  323. 8x +  y -  z =  8
  324. 2x +  y + 9z = 12
  325.  x - 7y + 2z = -4
  326. and solve them by a different method, called Gauss-Seidel 
  327. iteration. In each equation, find the variable whose coefficient 
  328. has the largest absolute value, and put that variable on one 
  329. side:
  330.      1    1
  331. x = - y +  z + 1
  332.      8    8
  333.  
  334.      2    1    4
  335. z = - x -  y +
  336.      9    9    3
  337.  
  338.      1    2    4
  339. y =   x +  z +
  340.      7    7    7
  341. Begin by guessing that x, y, and z are all 0, then improve the 
  342. guesses by using those equations. Here are the calculations, to 
  343. three decimal places:
  344. x = 0
  345. y = 0
  346. z = 0
  347.      1    1
  348. x = - y +  z + 1 = 1.000
  349.      8    8
  350.  
  351.      1    2    4
  352. y =   x +  z +   =  .714
  353.      7    7    7
  354.  
  355.      2    1    4
  356. z = - x -  y +   = 1.032
  357.      9    9    3
  358.  
  359.      1    1
  360. x = - y +  z + 1 = 1.041
  361.      8    8
  362.  
  363.      1    2    4
  364. y =   x +  z +   = 1.014
  365.      7    7    7
  366.  
  367.      2    1    4
  368. z = - x -  y +   =  .990
  369.      9    9    3
  370.  
  371.      1    1
  372. x = - y +  z + 1 =  .997
  373.      8    8
  374.  
  375.      1    2    4
  376. y =   x +  z +   =  .996
  377.      7    7    7
  378.  
  379.      2    1    4
  380. z = - x -  y +   = 1.002
  381.      9    9    3
  382.  
  383.      1    1
  384. x = - y +  z + 1 = 1.001
  385.      8    8
  386.  
  387.      1    2    4
  388. y =   x +  z +   = 1.000
  389.      7    7    7
  390.  
  391.      2    1    4
  392. z = - x -  y +   = 1.000
  393.      9    9    3
  394.  
  395.      1    1
  396. x = - y +  z + 1 = 1.000
  397.      8    8
  398.  
  399.      1    2    4
  400. y =   x +  z +   = 1.000
  401.      7    7    7
  402.  
  403.      2    1    4
  404. z = - x -  y +   = 1.000
  405.      9    9    3
  406. In the example, x and y and z gradually approach the correct 
  407. solutions.
  408.                                          Is Gauss-Seidel 
  409. iteration better or worse than Gauss-Jordan elimination?
  410.                                          A disadvantage of 
  411. Gauss-Seidel iteration is: it doesn't guarantee you'll approach 
  412. the correct solution. If you follow the advice about pivoting on 
  413. the coefficient that has the largest relative absolute value, you 
  414. stand a better chance of approaching the correct solution, but 
  415. there's no guarantee.
  416.                                          On the other hand, if 
  417. Gauss-Seidel iteration does approach a solution, the solution 
  418. will have less round-off error than with Gauss-Jordan 
  419. elimination.